// JavaScript Document
var typePage = {
	level_2: '',
	category: function (pid, level) {
		var data = { pid: pid };
		$.commonAjax({
			url: 'B012',
			type: 'POST',
			data: data,
			isShowError: true,
			success: function (res) {
				console.log(res.data);
				typePage.typeShow(res.data, level)
			}, error: function (res) {
				$.layermsg(res.msg);
			}
		})
	}, typeShow: function (data, level) {
		var htm = ''
		typePage.level_2 = '';
		$.each(data, function (k, v) {
			switch (level) {
				case 1: htm += '<li id="active_' + v.id + '" onClick="typePage.category(' + v.id + ',' + (v.level + 1) + ')" class="type-list ' + (k == 0 ? 'type-list-active' : '') + '"><p>' + v.name + '</p></li>'; break;
				case 2:
					if (data.length > 8) {
						if (k < 7) {
							htm += '<li onClick="bp.jump_data(\'shopList.html?categroyId='+v.id+'\');" class="infoName"><p>' + v.name + '</p></li>';
						} else {
							typePage.level_2 += '<li  onClick="bp.jump_data(\'shopList.html?categroyId='+v.id+'\');" class="infoName"><p>' + v.name + '</p></li>';
						}
					} else {
						htm += '<li onClick="bp.jump_data(\'shopList.html?categroyId='+v.id+'\');" class="infoName"><p>' + v.name + '</p></li>';
					}
					break;
			}
		});

		switch (level) {
			case 1: $('.type-nav').html(htm); typePage.category(data[0].id, 2); break;
			case 2:
				if (data.length > 8) {
					htm += '<li onClick="typePage.more()"  class="fold"></li>';
				}
				$('.info-box').html(htm); 
				$('.type-nav').children('li').removeClass('type-list-active'); $('#active_' + data[0].pid).addClass('type-list-active');
				break;
		}

	}, more: function () {
		$('.fold').before(typePage.level_2);
		$('.fold').hide();
	}
}


$(function () {
	$('.searchIcon-gray').click(function(){
        var val = $('.search-city').val();
        if(val.length){
            bp.jump_data('shopList.html?keyword='+val);
        }   
    });
	$('.tit').click(function(){
		bp.jump('shopList');
	});
	$('.backArrow').click(function () {
		bp.goback();
	});
	typePage.category(0, 1);
})